﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tool.Model
{
    public class GetColorEntity
    {
        /// <summary>
        /// 颜色
        /// </summary>
        public string ColorStr {  get; set; }
        /// <summary>
        /// 偏色
        /// </summary>
        public string ColorCastStr { get; set; } = "000000";
        /// <summary>
        /// 颜色坐标
        /// </summary>
        public Point Location { get; set; } 
       
    }
    public class GetColorListEntity
    {
        /// <summary>
        /// 各颜色点
        /// </summary>
        public List<GetColorEntity> List { get; set; }= new List<GetColorEntity>();
        /// <summary>
        /// 首点颜色字符串
        /// </summary>
        public string FirstColorStr { get; set; } = "";
        /// <summary>
        /// 其他点颜色字符串
        /// </summary>
        public string OtherColorStr { get; set; } = "";

        /// <summary>
        /// 初始化，拼接颜色字符串
        /// </summary>
        /// <param name="colorCast"></param>
        public void Init(string colorCast=null)
        {
            FirstColorStr = "";
            OtherColorStr = "";
            if (string.IsNullOrEmpty(colorCast))
            {
                if (List.Any())
                {
                    FirstColorStr = "\"" + List[0].ColorStr + "-" + List[0].ColorCastStr + "\"";
                    //拼接其他颜色字符串
                    for(int i = 1; i < List.Count; i++)
                    {
                        if (!string.IsNullOrEmpty(OtherColorStr)&& !OtherColorStr.EndsWith(","))
                        {
                            OtherColorStr += ",";
                        }
                        var xstr= (List[i].Location.X - List[0].Location.X).ToString();
                        var ystr= (List[i].Location.Y - List[0].Location.Y).ToString();
                        OtherColorStr = OtherColorStr + xstr + "|" + ystr + "|" + List[i].ColorStr + "|" + "" + List[i].ColorCastStr;
                    }
                    if (!string.IsNullOrEmpty(OtherColorStr))
                    {
                        OtherColorStr = "\"" + OtherColorStr + "\"";
                    }
                }
            }
            else
            {
                if (List.Any())
                {
                    FirstColorStr = "\""+  List[0].ColorStr + "-" + colorCast+ "\"";
                    //拼接其他颜色字符串
                    for (int i = 1; i < List.Count; i++)
                    {
                        if (!string.IsNullOrEmpty(OtherColorStr) && !OtherColorStr.EndsWith(","))
                        {
                            OtherColorStr += ",";
                        }
                        var xstr = (List[i].Location.X - List[0].Location.X).ToString();
                        var ystr = (List[i].Location.Y - List[0].Location.Y).ToString();
                        OtherColorStr = OtherColorStr + xstr + "|" + ystr + "|" + List[i].ColorStr + "|" + "" + colorCast;
                    }
                    if (!string.IsNullOrEmpty(OtherColorStr))
                    {
                        OtherColorStr = "\"" + OtherColorStr + "\"";
                    }
                }
            }
           
        }
    }
}
